package ericXie.com.model 
{
	import ericXie.com.component.HaloMovieClip;
	import ericXie.com.component.PopUpWindowMovieClip;
	import ericXie.com.component.RouletteMovieClip;
	import ericXie.com.events.LoadLibFinshEvent;
	import ericXie.com.events.PopUpWindowEvent;
	import ericXie.com.events.SimpleButtonAshyEvent;
	import ericXie.com.events.StartRouletteEvent;
	import flash.display.InteractiveObject;
	import flash.display.LoaderInfo;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.EventDispatcher;

	
	
	/**
	 * 单例模式，数据中心存储器
	 * @author EricXie
	 */
	public class MainModel extends EventDispatcher 
	{
		//单例
		private static var _intance:MainModel;
		//Arr配置数据
		private var _getData:Array;
		//主界面
		private var _mainApp:Sprite;
		//SWF库信息
		private var _libElement:LoaderInfo;
		//转盘
		private var _roulette:RouletteMovieClip;
		//中心旋转区
		private var _halo:HaloMovieClip;
		//初始化剩余次数
		private var _initResidueNum:Number;
		//弹出信息窗
		private var _popupWindow:PopUpWindowMovieClip;
		//开始按钮
		private var _startBn:SimpleButton;
		//转盘奖品对应区域
		public var roulettePrize:Array = [3, 5, 1, 7, 8, 2, 4, 6];
		//获取转盘信息地址
		public static const START_ROULETTE_PATH:String = "http://kids.damai.cn/CjAjax.aspx?_action=GetCjResult&pfig=80720F3C138A449A9096B5ED9E1E9947&timer=";
		
	
	
		public function MainModel() 
		{
			
		}
		//单例
		public static function getInstance():MainModel
		{
			if (_intance == null) {
				_intance = new MainModel();
			}
			return _intance;
		}
		
		public function extractionElements(mcName:String):InteractiveObject
		{
			var movieElement:Class = libElement.applicationDomain.getDefinition(mcName) as Class;
			var mc:InteractiveObject = new movieElement() as InteractiveObject;
			return mc;
		}
		
		//XML配置数据
		public function get getData():Array 
		{
			return _getData;
		}
		
		public function set getData(value:Array):void 
		{
			_getData = value;
			if (Number(_getData[0]) != 0) {
				new StartRouletteEvent().dispatch();
			}else {
				new PopUpWindowEvent(PopUpWindowEvent.POPUP_TYPE).dispatch();
			}
		}
		//主界面
		public function get mainApp():Sprite 
		{
			return _mainApp;
		}
		
		public function set mainApp(value:Sprite):void 
		{
			_mainApp = value;
		}
		
		public function get libElement():LoaderInfo 
		{
			return _libElement;
		}
		
		public function set libElement(value:LoaderInfo):void 
		{
			_libElement = value;
			dispatchEvent(new LoadLibFinshEvent());
		}
		
		public function get roulette():RouletteMovieClip 
		{
			return _roulette;
		}
		
		public function set roulette(value:RouletteMovieClip):void 
		{
			_roulette = value;
		}
		
		public function get halo():HaloMovieClip 
		{
			return _halo;
		}
		
		public function set halo(value:HaloMovieClip):void 
		{
			_halo = value;
		}
		
		
		public function get popupWindow():PopUpWindowMovieClip 
		{
			return _popupWindow;
		}
		
		public function set popupWindow(value:PopUpWindowMovieClip):void 
		{
			_popupWindow = value;
		}
		
		public function get startBn():SimpleButton 
		{
			return _startBn;
		}
		
		public function set startBn(value:SimpleButton):void 
		{
			_startBn = value;
		}
		
		public function get initResidueNum():Number 
		{
			return _initResidueNum;
		}
		
		public function set initResidueNum(value:Number):void 
		{
			_initResidueNum = value;
			if (_initResidueNum == 0) {
			//	new PopUpWindowEvent(PopUpWindowEvent.POPUP_TYPE).dispatch();
				new SimpleButtonAshyEvent(startBn, false).dispatch();
			}
		}

		
		

		
	}

}